//
//  DSYITCollectionViewCell.m
//  BLDMusics
//
//  Created by dllo on 16/3/18.
//  Copyright © 2016年 李晓丹. All rights reserved.
//

#import "DSYITCollectionViewCell.h"
#import "DSYCarouselModel.h"

#define HOLDER [UIImage imageNamed:@"recommend_header_placeholder.jpg"]
@interface DSYITCollectionViewCell ()

@property (nonatomic, retain) UIImageView *picView;
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *listenCountLabel;  /**< 显示被听得次数 */
@property (nonatomic, retain) UIImageView *iconImgView;     /**< 图标 */

@end

@implementation DSYITCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubviews];
    }
    return self;
}

- (void)creatSubviews {
    
    self.picView = [[UIImageView alloc] init];
    [self.contentView addSubview:_picView];
    
    self.nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_nameLabel];
    
    self.listenCountLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_listenCountLabel];
    
    self.iconImgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_iconImgView];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    _picView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height - 40);

    CGSize size = [APPTools labelRectWithSize:CGSizeMake(self.contentView.frame.size.width, 0) labelText:_sourceModel.name Font:[UIFont systemFontOfSize:13.0]];
    _nameLabel.frame = CGRectMake(0, CGRectGetMaxY(_picView.frame), CGRectGetWidth(_picView.frame), size.height);
    _nameLabel.font = [UIFont systemFontOfSize:13.0f];
//    _nameLabel.backgroundColor = [UIColor greenColor];
    _nameLabel.numberOfLines = 0;

    
}

- (void)setSourceModel:(DSYCarouselModel *)sourceModel
{
    _sourceModel = sourceModel;
    
    [_picView sd_setImageWithURL:[NSURL URLWithString:_sourceModel.picUrl] placeholderImage:HOLDER];
    CGSize size = [APPTools labelRectWithSize:CGSizeMake(self.contentView.frame.size.width, 0) labelText:_sourceModel.name Font:[UIFont systemFontOfSize:13.0]];

   // NSLog(@"%f", size.height);


    _nameLabel.frame = CGRectMake(0, CGRectGetMaxY(_picView.frame), CGRectGetWidth(_picView.frame), size.height);
    _nameLabel.text = _sourceModel.name;
}

@end
